# Class ASTVar
# Inherits from AST, represents the implementation of an AST that represents a 
# variable of the programming language 'Vectorinox'
class ASTVar < AST
  # Node of the AST
  attr_reader :node
  # Array containing the names of the variables
  attr_reader :names
  # Array containing the types of the variables
  attr_reader :type
  attr_writer :type

  # Constructor of the class
  # === Parameters
  # * node -> main node of the AST
  # * names -> Array containing the types of the variables
  def initialize node, names
    @node = node
    @names = names
    @type = nil == @node ? nil : @node.value
  end

  # Returns the closest wrong token to the place were an error is generated
  def error_tk
    for tk in @names
      if nil != tk
        return tk
      end
    end
    if nil != @node
      return @node
    end
    nil
  end

  # Creates a 'String' representation of the AST with 'i' identation spaces
  # === Parameters
  # * i: Identation with which the AST should be printed with
  def to_s i
    output = "(Declaración de variables de tipo #{type.to_s}: "
    for name in names
      output += "#{name}, "
    end
    output[0, output.length - 3] + ")"
  end
end